<?php

namespace Cyfy\Modules\Errors\Forms;

use \Cyfy\Message;
use \Cyfy\Modules\Forms;
use \Cyfy\Modules\Errors\Module;
use \Cyfy\Modules\BasicContent\Content;

/** 
 * Edits 404 page
 */
class Edit404 extends Forms\Form
{
	function structure()
	{	
        $this -> stay = true;

        $i = new Forms\TextBox("title", self :: t(30));
		$i -> required = true;
        $this -> AddItem($i);
		
		$w = new Forms\WysiwygEditor("content", self :: t(40));
		$w -> required = true;
		$this -> AddItem($w);
		
		$b = new Forms\Button(self :: t(50));
		$this -> AddButton($b);
    }
  
	function submit()
	{  
        $content = Content :: load(Module :: constant("404"));
        
        // if not, load new
        if(!$content)
        {
            $content = new Content();
        }
        
        $content -> setTitle($this -> get("title"));
        $content -> setContent($this -> get("content"));
        $content -> save();
        
        Message :: set(self :: t(60));
        return true;     
	}	
}